#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back
#define y1 yyyyyyyyyy________1

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 1e6+10;
const int mod = 1e9+7;

int lz[N<<2],n,m,k;
ll val[N<<2];
vector<pii> add[N],del[N];
set<pii> s;

void pushdown(int o){if(lz[o]){lz[o<<1] = lz[o<<1|1] = 1; val[o<<1] = val[o<<1|1] = 0; lz[o] = 0;}}

void update(int pos,int v,int o = 1,int l = 1,int r = m){
	if(l == r) return val[o] = v,void(); pushdown(o);
	int mid = l+r>>1; if(pos <= mid) update(pos,v,o<<1,l,mid);else update(pos,v,o<<1|1,mid+1,r); (val[o] = val[o<<1] + val[o<<1|1]) %= mod;
}

void clear(int xl,int xr,int o = 1,int l = 1,int r = m){
	if(xl == l && xr == r) return val[o] = 0,lz[o] = 1,void(); pushdown(o);
	int mid = l+r>>1; if(xr <= mid) clear(xl,xr,o<<1,l,mid);else if(xl > mid) clear(xl,xr,o<<1|1,mid+1,r); else clear(xl,mid,o<<1,l,mid),clear(mid+1,xr,o<<1|1,mid+1,r); (val[o] = val[o<<1] + val[o<<1|1]) %= mod;
}

ll query(int xl,int xr,int o = 1,int l = 1,int r = m){
	if(xl == l && xr == r) return val[o]; pushdown(o);
	int mid = l+r>>1; if(xr <= mid) return query(xl,xr,o<<1,l,mid); else if(xl > mid) return query(xl,xr,o<<1|1,mid+1,r);else return (query(xl,mid,o<<1,l,mid) + query(mid+1,xr,o<<1|1,mid+1,r)) % mod;
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in,m = in,k = in;
	for(int i = 1;i <= k;i++){
		int x1 = in,y1 = in,x2 = in,y2 = in;
		add[x1].pb(pii(y1,y2)); del[x2+1].pb(pii(y1,y2));
	}
	s.insert(pii(0,0));
	for(pii x : add[1]) s.insert(x); update(1,1);
	for(int i = 2;i <= n;i++){
		sort(add[i].begin(),add[i].end(),greater<pii>());
		for(pii cur : add[i]){
			int x = cur.fi,y = cur.se; ll ans = 0; if(y == m) continue;
			set<pii> :: iterator it = s.lower_bound(pii(y+2,0)); it--;
			if((*it).se <= y) ans = query((*it).se+1,y+1) % mod;
			update(y+1,ans); 
		}
		for(pii cur : del[i]) s.erase(cur);
		for(pii cur : add[i]) clear(cur.fi,cur.se), s.insert(cur);
	}
	set<pii> :: iterator it = s.end(); it--;
	ll ans = query((*it).se+1,m);
	printf("%lld\n",ans);
	return 0;
}

